package com.lincolnXmypcqq.netty;

import com.lincoln.framework.annotation.Execute;
import com.lincoln.framework.bean.AbstractMsgNoExecute;
import com.lincoln.framework.bean.AbstractMsgNoProtocol;
import com.lincoln.framework.interfaces.BaseProtocol;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 处理聊天
 * @author lincoln
 */
@Execute(deviceType = 1, protocolType = 0)
public class DealChat extends AbstractMsgNoExecute {
    private static Logger logger = LoggerFactory.getLogger(DealChat.class);
    private static final int LENGTH = 6;
    private static final int SUCCESS = 1;
    //服务器发过去的
    public static String SERVER_CMD = "发送消息";
    //客户端发过来的
    public static String CLIENT_CMD = "聊天消息";

    @Override
    public byte[] getServerCmd() {
        return SERVER_CMD.getBytes();
    }

    @Override
    public byte[] getClientCmd() {
        return CLIENT_CMD.getBytes();
    }

    @Override
    public Logger getLogger() {
        return logger;
    }

    @Override
    public boolean decoder(BaseProtocol baseProtocol) {
        if (baseProtocol.size() < LENGTH || baseProtocol.getCmd() == null) {
            return false;
        }
        logger.info("识别为聊天消息-消息号为:" + ((AbstractMsgNoProtocol) baseProtocol).getNo());
        return true;
    }

    @Override
    public boolean execute(BaseProtocol baseProtocol) {
        AbstractMsgNoProtocol reply = new AbstractMsgNoProtocol(getServerCmd(), new byte[]{SUCCESS});
        return send(reply);
    }

    @Override
    public boolean send(byte[] payload) {
        return super.send(payload);
    }
}
